<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>新增收货地址</title>
    <link rel="stylesheet" type="text/css" href="__CSS__/api.css"/>
    <link rel="stylesheet" type="text/css" href="__CSS__/aui.css"/>
    <style>
        .contain {
            padding: 0 0.75rem;
            background-color: #fff;
        }

        .left_title {
            color: #555555;
            font-size: 14px;
            height: 2.5rem;
            line-height: 2.5rem;
            text-align: left;
        }

        input[type="text"],
        input[type="tel"] {
            color: #555555;
            font-size: 14px;
            margin-top: 0;
            background-color: #fff;
            height: 2.45rem;
            padding-left: 0.5rem;
        }

        input[type="text"]::-webkit-input-placeholder,
        input[type="tel"]::-webkit-input-placeholder,
        textarea::-webkit-input-placeholder {
            font-size: 14px;
            color: #B7B7B7;
        }

        .button {
            font-size: 15px;
            color: #FFFFFF;
            width: 91%;
            height: 1.8rem;
            line-height: 1.8rem;
            text-align: center;
            background: -webkit-linear-gradient(right, #F04040, #FF7A7A);
            margin: 0 auto;
            margin-top: 2.5rem;
            border-radius: 2px;
        }

        input[type="radio"] {
            -webkit-appearance: none;
            width: 0.95rem;
            height: 0.95rem;
            vertical-align: middle;
            background: #fff url(__IMG__/check_no.png) no-repeat center center;
            background-size: 0.95rem 0.95rem;
            border-radius: 50%;
            margin-right: 0.7rem;
            margin-top: 0.75rem;

        }

        input[type="radio"]:checked {
            -webkit-appearance: none;
            width: 0.95rem;
            height: 0.95rem;
            vertical-align: middle;
            background: #fff url(__IMG__/choose_yes.png) no-repeat center center;
            background-size: 0.95rem 0.95rem;
            border-radius: 50%;
        }

        .contain1 {
            font-size: 14px;
            color: #555;
            height: 2.5rem;
            line-height: 2.5rem;
            padding-left: 3.3rem;
        }

        .gender {
            padding-right: 1.75rem;
        }

        .local {
            width: 0.675rem;
            height: 0.8rem;
            margin-left: 5.5px;
            margin-top: 0.85rem;
        }
    </style>
</head>

<body>
<div class="contain">
    <div class="flex-wrap underLine">
        <div class="left_title">联系人：</div>
        <div class="flex-con">
            <input type="text" placeholder="请填写收货人的姓名" id='name' value="{$data.name}"/>
        </div>
    </div>
</div>
<div class="contain">
    <div class="contain1 flex-wrap underLine">
        <input type="radio" name="radio" value='1' {if $data.sex==1} checked {/if}/>
        <div class="gender">先生</div>
        <input type="radio" name="radio" value='2' {if $data.sex==2} checked {/if}/>
        <div>女士</div>
    </div>
</div>
<div class="contain">
    <div class="flex-wrap underLine">
        <div class="left_title">手机号：</div>
        <div class="flex-con">
            <input type="tel" placeholder="请填写收货手机号" maxlength="11" id="phone" value="{$data.phone}"/>
        </div>
    </div>
</div>
<div class="contain" tapmode="active" onclick="openMap()">
    <div class="flex-wrap underLine">
        <div class="left_title">收货地址:</div>
        <div class="local"><img src="__IMG__/local3.png" alt=""></div>
        <div class="flex-con">
            <input type="text" placeholder="点击选择" readonly id='address' value="{$data.address}"/>
        </div>
    </div>
</div>
<div class="contain">
    <div class="flex-wrap underLine">
        <div class="left_title">门牌号：</div>
        <div class="flex-con">
            <input type="text" placeholder="例如：A座906室" id='door' value="{$data.door}"/>
        </div>
    </div>
</div>

<div class="button" tapmode="active" onclick="saveMyDiZhi()">保存地址</div>
</body>
<input type="hidden" id="lat" value="{$data.lat}"/>
<input type="hidden" id="lon" value="{$data.lon}"/>
<script type="text/javascript" src="__JS__/jquery.min.js"></script>
<script type="text/javascript" src="__JS__/tt222.js"></script>
<script type="text/javascript">
    //保存地址
    function saveMyDiZhi() {
        var param = getAddAddress2Param(1);
        if (param.name == '') {
            alert('请填写姓名');
            return
        } else if (param.phone == '') {
            alert('请填写电话');
            return
        } else if (param.address == '') {
            alert('请选择地址');
            return
        } else if (param.sex == '') {
            alert('请选择性别');
            return
        }else{
            var str = getAddAddress2Param(2);
            $.ajax({
                url:'{:url("Index/addMyAddress")}',
                data: str,//
                type:'POST',
                dataType:'JSON',
                success: function(returndata){
                    if(returndata.status == 200){
                        var lat = {$lat};
                        var lon = {$lon};
                        var sid = {$shopid};
                        location.href = '{:url("home/Car/getNearAddress")}?lat='+lat+'&lon='+lon+'&shopid='+sid;
                    }else{
                        alert(returndata.msg);
                    }
                },
                error:function () {
                    alert('Ajax error!');
                }
            })
        }
    }

    //收货地址定位
    function openMap() {
        var str = getAddAddress2Param(2);
        var lat = {$lat};
        var lon = {$lon};
        var sid = {$shopid};
        location.href = '{:url("home/Car/addressLocation")}?' + str+'&lat2='+lat+'&lon2='+lon+'&shopid='+sid;
    }
    pushHistory();
    window.addEventListener("popstate", function(e) {
        var lat = {$lat};
        var lon = {$lon};
        var sid = {$shopid};
        location.href = '{:url("home/Car/getNearAddress")}?lat='+lat+'&lon='+lon+'&shopid='+sid;
    }, false);
    function pushHistory() {
        var state = {
            title: "title",
            url: "#"
        };
        window.history.pushState(state, "title", "#");
    }
    XBack.listen(function(){
        alert('back');
    });
</script>

</html>
